﻿@using System.Runtime.InteropServices
@model dynamic
@{
    ViewBag.Title = L("部门管理");
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
<div id="app">
    <i-table border :columns="cols" :data="rows"></i-table>
</div>
@section scripts{
    <script type="text/javascript">
        $(function () {
            var service = abp.services.app.departmentService;
            window.view = new Vue({
                el: "#app",
                data: {
                    cols: [
                        {
                            title: '姓名',
                            key: 'name'
                        },
                        {
                            title: '操作',
                            key: 'action',
                            width: 150,
                            align: 'center',
                            render: function (h, params) {
                                return h('div',
                                    [
                                        h('Button',
                                            {
                                                props: {
                                                    type: 'primary',
                                                    size: 'small'
                                                },
                                                style: {
                                                    marginRight: '5px'
                                                },
                                                on: {
                                                    click: function () {
                                                        view.edit(params.row);
                                                    }
                                                }
                                            },
                                            '编辑'),
                                        h('Button',
                                            {
                                                props: {
                                                    type: 'error',
                                                    size: 'small'
                                                },
                                                on: {
                                                    click: function () {
                                                        view.remove(params.row);
                                                    }
                                                }
                                            },
                                            '删除')
                                    ]);
                            }
                        }
                    ],
                    rows: []
                },
                methods: {
                    remove: function (row) {
                        window.abp.message.confirm("确认删除？")
                            .done(function () {
                                service.remove({ id: row.id }).done(function () {
                                    service.getAll()
                                        .done(function (data) {
                                            view.rows = data.items;
                                        });
                                });
                            });
                    },
                    edit: function (row) {
                        window.location = "@Url.Action("DepartmentEdit","Admin")/?" + $.param({ id: row.id});
                    }
                }
            });
            service.getAll()
                .done(function (data) {
                    view.rows = data.items;
                });
        });
    </script>
}
